﻿//----------------------------------------------------------------
// <copyright file="PrivilegeInRolesBLL.cs" >
//    Copyright (c) Wenzy , All rights reserved.
//    author:温正宇 E-Mail:wenzy@tom.com　MyBlog:wenzy.cnblogs.com
//    All rights reserved.
// </copyright>
//----------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using MemberShipDAL.DataObject.DataResourcesTableAdapters;
using MemberShipDAL.DataObject;
using System.Windows.Forms;

namespace WMFConfig.Bussiness
{
    public class PrivilegeInRolesBLL
    {
        /// <summary>
        /// 删除正在使用的权限
        /// </summary>
        /// <param name="operationId"></param>
        /// <param name="resourcesId"></param>
        public void DeletePrivilegeInRoles(int operationId, Guid resourcesId)
        {
            //获得当前权限的ID
            Guid? privilegeId = new wmf_PrivilegeTableAdapter().GetPrivilegeIdByOptResId(operationId, resourcesId);

            DeletePrivilegeInRoles(privilegeId.Value);
        }

        public void DeletePrivilegeInRoles(Guid privilegeId)
        {
            wmf_PrivilegeInRolesTableAdapter pDa = new wmf_PrivilegeInRolesTableAdapter();

            int i = (int)pDa.CountByPrivilegeId(privilegeId);

            //如果PrivilegeID有在PrivilegeInRoles表里面，表示有在使用，那么就要删除
            if (i != 0)
            {
                //如果用户确认删除
                if (MessageBox.Show("您确认要删除正在使用的权限[" + privilegeId + "]吗？", "删除提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    i = pDa.DeleteByPrivilegeId(privilegeId);
                }
                //要做一个系统优化的功能，把没有删除干净的权限清理掉
            }

        }
    }
}
